package models

import (
	"time"
	"user_srv/basic/config"
)

// SwipeRecord 滑动记录表：记录用户的滑动行为
// 表名：swipe_record
type SwipeRecord struct {
	Id         uint64    `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	UserId     uint64    `gorm:"column:user_id;type:bigint UNSIGNED;index;not null;comment:滑动用户ID;" json:"user_id"`
	TargetId   uint64    `gorm:"column:target_id;type:bigint UNSIGNED;index;not null;comment:被滑动用户ID;" json:"target_id"`
	Action     int8      `gorm:"column:action;type:tinyint(1);not null;comment:滑动动作 1-左滑无感 2-右滑喜欢;" json:"action"`
	MatchScore float64   `gorm:"column:match_score;type:decimal(5,4);default:0;comment:匹配分数;" json:"match_score"`
	CreatedAt  time.Time `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt  time.Time `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt  time.Time `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

// TableName 返回 SwipeRecord 对应的数据库表名："swipe_record"
func (SwipeRecord) TableName() string {
	return "swipe_record"
}

// GetByUserAndTarget 根据用户ID和目标用户ID获取滑动记录
func (s *SwipeRecord) GetByUserAndTarget() error {
	return config.DB.Where("user_id = ? AND target_id = ?", s.UserId, s.TargetId).First(&s).Error
}

// Create 创建滑动记录
func (s *SwipeRecord) Create() error {
	return config.DB.Create(&s).Error
}
